package org.jeecg.modules.monitoring.j_monitoring.controller;

import jakarta.servlet.http.HttpServletRequest;

import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.modules.monitoring.j_monitoring.entity.GatewaySystemFdn;
import org.jeecg.modules.monitoring.j_monitoring.service.IGatewaySystemFdnService;
import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

/**
 * @Description: 网关系统FDN
 * @Author: xiaoyq
 * @Date: 2023-05-04
 * @Version: V1.0
 */
@Api(tags = "网关系统FDN")
@RestController
@RequestMapping("/gatewaySystemFdn/gatewaySystemFdn")
@Slf4j
public class GatewaySystemFdnController extends JeecgController<GatewaySystemFdn, IGatewaySystemFdnService> {
    @Autowired
    private IGatewaySystemFdnService gatewaySystemFdnService;

    /**
     * 分页列表查询
     *
     * @param gatewaySystemFdn
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "网关系统FDN-分页列表查询")
    @ApiOperation(value = "网关系统FDN-分页列表查询", notes = "网关系统FDN-分页列表查询")
    @GetMapping(value = "/list")
    public Result<IPage<GatewaySystemFdn>> queryPageList(GatewaySystemFdn gatewaySystemFdn,
                                                         @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                         @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                         HttpServletRequest req) {
        QueryWrapper<GatewaySystemFdn> queryWrapper = QueryGenerator.initQueryWrapper(gatewaySystemFdn, req.getParameterMap());
        Page<GatewaySystemFdn> page = new Page<GatewaySystemFdn>(pageNo, pageSize);

        IPage<GatewaySystemFdn> pageList = gatewaySystemFdnService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    /**
     * 添加
     *
     * @param gatewaySystemFdn
     * @return
     */
    @AutoLog(value = "网关系统FDN-添加")
    @ApiOperation(value = "网关系统FDN-添加", notes = "网关系统FDN-添加")
    //@RequiresPermissions("org.jeecg.modules.monitoring:网关系统FDN:add")
    @PostMapping(value = "/add")
    public Result<String> add(@RequestBody GatewaySystemFdn gatewaySystemFdn) {
        gatewaySystemFdnService.save(gatewaySystemFdn);
        return Result.OK("添加成功！");
    }

    @GetMapping("/test")
    public void test() {
        gatewaySystemFdnService.syncIPInterface();
    }


    //获取实时数据 type: 1.网络资源 2.计算资源 3.虚拟机 4.存储资源
    @GetMapping(value = "/getGatewayData")
    public Result getGatewayData(
            @RequestParam(name = "type", defaultValue = "1") Integer type,
            @RequestParam(name = "id") String id) {

        return gatewaySystemFdnService. getGatewayData(type,id);
    }


    @GetMapping(value = "/showIpInterface")
    public Result showIpInterface(
            @RequestParam(name = "type", defaultValue = "1") Integer type,
            @RequestParam(name = "id") String id) {

        return gatewaySystemFdnService.showIpInterface(type,id);
    }

    @ApiOperation(value = "获取网络设备列表视图接口", notes = "获取网络设备列表视图接口")
    @GetMapping(value = "/getIpInterfaceList")
    public Result getIpInterfaceList(@RequestParam(name = "id") String id) {

        return gatewaySystemFdnService.getIpInterfaceList(id);
    }

    @ApiOperation(value = "网络设备流量视图", notes = "网络设备流量视图")
    @GetMapping(value = "/NetWorkFlowList")
    public Result NetWorkFlowList(@RequestParam(name = "id") String id,@RequestParam(name = "name") String name) {

        return gatewaySystemFdnService.NetWorkFlowList(id,name);
    }

    //添加至资源监控 type: 1.网络资源 2.计算资源 3.虚拟机 4.存储资源 5.虚拟化集群
    @GetMapping(value = "/insertMonitor")
    public Result insertMonitor(
            @RequestParam(name = "type", defaultValue = "1") Integer type,
            @RequestParam(name = "id") String id) {

        return gatewaySystemFdnService.insertMonitor(type,id);
    }


    @GetMapping(value = "/virtualClusterInfo")
    public Result virtualClusterInfo(
            @RequestParam(name = "name", defaultValue = "") String name,
            @RequestParam(name = "ip") String ip) {

        return gatewaySystemFdnService.virtualClusterInfo(name,ip);
    }

    @GetMapping(value = "/machineInfo")
    public Result machineInfo(
            @RequestParam(name = "name", defaultValue = "") String name) {

        return gatewaySystemFdnService.machineInfo(name);
    }


}
